package com.doudou.casebook.utils;

import static androidx.core.content.ContentProviderCompat.requireContext;
import static androidx.core.content.ContextCompat.startActivity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.doudou.casebook.AboutActivity;
import com.doudou.casebook.HistoryActivity;
import com.doudou.casebook.MonthchartActivity;
import com.doudou.casebook.R;
import com.doudou.casebook.SearchActivity;
import com.doudou.casebook.SettingActivity;

public class MoreDialog extends Dialog implements View.OnClickListener {
    Button infoBtn,settingBtn,aboutBtn,recordBtn;
    ImageView iv;
    private Context mContext;
    public MoreDialog(@NonNull Context context) {
        super(context);
        mContext =context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_more);

        infoBtn=findViewById(R.id.dialog_more_btn_info);
        settingBtn=findViewById(R.id.dialog_more_btn_setting);
        aboutBtn=findViewById(R.id.dialog_more_btn_about);
        recordBtn=findViewById(R.id.dialog_more_btn_record);
        iv = findViewById(R.id.dialog_more_iv);

        infoBtn.setOnClickListener(this);
        settingBtn.setOnClickListener(this);
        aboutBtn.setOnClickListener(this);
        recordBtn.setOnClickListener(this);
        iv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();

        if (v.getId()==R.id.dialog_more_btn_info){
            intent.setClass(getContext(), MonthchartActivity.class);
            getContext().startActivity(intent);

        } else if (v.getId()==R.id.dialog_more_btn_setting) {
           intent.setClass(getContext(), SettingActivity.class);
           getContext().startActivity(intent);

        }else if (v.getId()==R.id.dialog_more_btn_about) {
            intent.setClass(getContext(), AboutActivity.class);
            getContext().startActivity(intent);

        }else if (v.getId()==R.id.dialog_more_btn_record) {
            intent.setClass(getContext(), HistoryActivity.class);
            getContext().startActivity(intent);

        }

        cancel();
    }

    //设置dialog尺寸与屏幕尺寸一样宽
    public void setDialogSize(){
        //获取窗口对象
        Window window = getWindow();
        //获取对象参数
        assert window != null;
        WindowManager.LayoutParams wlp = window.getAttributes();
        //获取屏幕宽度
        Display d = window.getWindowManager().getDefaultDisplay();
        wlp.width = d.getWidth();
        wlp.gravity = Gravity.BOTTOM;
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(wlp);

    }
}
